// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

namespace SnapObjects.Data.Odbc
{
    public class OdbcAseSqlGenerationHelper : OdbcSqlGenerationHelperBase, ISqlGenerationHelper
    {
        public OdbcAseSqlGenerationHelper(IDataContextOptions contextOptions): base(contextOptions) 
        {
        
        }

        protected override string LeftDelimitIdentifier => "\"";

        protected override string RightDelimitIdentifier => "\"";

        public override bool IsDelimitIdentifier(string left, string right)
        {
            var isDelimit = base.IsDelimitIdentifier(left, right);

            if (!isDelimit)
            {
                isDelimit = "[".Equals(left) && "]".Equals(right);
            }

            return isDelimit;
        }

        public override string RemoveDelimitIdentifier(string objectName)
        {
            if (!this.TryRemoveDelimitIdentifier(
                objectName, this.LeftDelimitIdentifier, this.RightDelimitIdentifier, out var name))
            {
                this.TryRemoveDelimitIdentifier(objectName, "[", "]", out name);
            }

            return name;
        }
    }
}
